package queue_stack.leetcode.easy;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author bruin_du
 * @description 最近请求次数
 * @date 2022/8/13 22:13
 **/
public class OfferII042_RecentCounter {
    Queue<Integer> queue;

    public OfferII042_RecentCounter() {
        queue = new LinkedList<Integer>();
    }

    public int ping(int t) {
        int time = t - 3000;
        while (!queue.isEmpty() && time > queue.peek()) {
            queue.poll();
        }
        queue.offer(t);
        return queue.size();
    }
}
